package arithmetic.thread.sync006;

/**
 * @author jiangfeng
 * Created on 2020-02-24
 */
public class StringInternTest {
    //https://blog.csdn.net/u013366617/article/details/83618361
    public static void main(String[] args) {
        String a1 = new String("AA");
        String a2 = new String("AA");
        System.out.println(a1 == a2); //false
        System.out.println(a1.intern() == a2.intern()); //true


        //如果常量池上不存在常量AA,也不存在引用AA，则创建常量AA
        String b1 = new String("AA");
        System.out.println(b1 == b1.intern()); //false

        System.out.println(b1.intern() == "AA"); //true
    }
}
